<template>
  <div class="qrcode-container">
    <el-card class="qrcode-card">
      <div class="qrcode-header">
        <h2>扫码支付</h2>
        <div class="amount">¥{{ amount }}</div>
      </div>

      <div class="qrcode-content">
        <div class="qrcode-wrapper">
          <img
            :src="paymentMethod === 'wechat' ? '/wechat-qr.png' : '/alipay-qr.png'"
            :alt="paymentMethod === 'wechat' ? '微信支付' : '支付宝'"
            class="qrcode-image"
          />
        </div>
        <div class="payment-type">
          <img
            :src="paymentMethod === 'wechat' ? '/wechat-logo.png' : '/alipay-logo.png'"
            :alt="paymentMethod === 'wechat' ? '微信支付' : '支付宝'"
            class="payment-logo"
          />
          {{ paymentMethod === 'wechat' ? '微信扫码支付' : '支付宝扫码支付' }}
        </div>
      </div>

      <div class="qrcode-actions">
        <el-button @click="goBack">返回</el-button>
        <el-button type="primary" @click="handlePaymentComplete" :loading="submitting">
          支付完成
        </el-button>
      </div>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { confirmDeposit } from '@/api/order'

const route = useRoute()
const router = useRouter()
const submitting = ref(false)

const amount = ref(route.query.amount)
const paymentMethod = ref(route.query.method)

const goBack = () => {
  router.back()
}

const handlePaymentComplete = async () => {
  submitting.value = true
  try {
    await confirmDeposit(Number(route.params.id))
    ElMessage.success('支付成功')
    router.push('/order-manage')
  } catch (error) {
    ElMessage.error('支付失败，请重试')
  } finally {
    submitting.value = false
  }
}
</script>

<style scoped>
.qrcode-container {
  padding: 40px 20px;
  max-width: 500px;
  margin: 0 auto;
  min-height: calc(100vh - 80px);
}

.qrcode-card {
  background: white;
  border-radius: 8px;
  text-align: center;
}

.qrcode-header {
  margin-bottom: 32px;
}

.qrcode-header h2 {
  margin-bottom: 16px;
  color: #333;
}

.amount {
  font-size: 32px;
  font-weight: bold;
  color: #f56c6c;
}

.qrcode-content {
  margin-bottom: 32px;
}

.qrcode-wrapper {
  width: 200px;
  height: 200px;
  margin: 0 auto 16px;
  padding: 10px;
  border: 1px solid #dcdfe6;
}

.qrcode-image {
  width: 100%;
  height: 100%;
}

.payment-type {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #666;
}

.payment-logo {
  width: 24px;
  height: 24px;
}

.qrcode-actions {
  display: flex;
  justify-content: center;
  gap: 16px;
}
</style>
